package com.heima.mvplibrary.utils;

import android.app.Dialog;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * author : liutiantian
 * e-mail : Tareafengye@163.com
 * date   : 2019-09-0310:31
 * desc   :
 * version: 1.0
 */
public class KnifeKit {
    public static Unbinder bind(Object target) {
        if (target instanceof AppCompatActivity) {
            return ButterKnife.bind((AppCompatActivity) target);
        } else if (target instanceof Dialog) {
            return ButterKnife.bind((Dialog) target);
        } else if (target instanceof View) {
            return ButterKnife.bind((View) target);
        }
        return Unbinder.EMPTY;
    }


    public static Unbinder bind(Object target, Object source) {
        if (source instanceof AppCompatActivity) {
            return ButterKnife.bind(target, (AppCompatActivity) source);
        } else if (source instanceof Dialog) {
            return ButterKnife.bind(target, (Dialog) source);
        } else if (source instanceof View) {
            return ButterKnife.bind(target, (View) source);
        }
        return Unbinder.EMPTY;
    }


    public static void unbind(Unbinder unbinder) {
        if (unbinder != Unbinder.EMPTY) {
            unbinder.unbind();
        }
    }
}
